﻿IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_SolicitudCotizacion_TipoProducto]') AND parent_object_id = OBJECT_ID(N'[dbo].[SolicitudCotizacion]'))
ALTER TABLE [dbo].[SolicitudCotizacion] DROP CONSTRAINT [FK_SolicitudCotizacion_TipoProducto]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_SolicitudCotizacion_Aplicada]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SolicitudCotizacion] DROP CONSTRAINT [DF_SolicitudCotizacion_Aplicada]
END

GO

/****** Object:  Table [dbo].[SolicitudCotizacion]    Script Date: 07/07/2011 17:42:21 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SolicitudCotizacion]') AND type in (N'U'))
DROP TABLE [dbo].[SolicitudCotizacion]
GO

/****** Object:  Table [dbo].[SolicitudCotizacion]    Script Date: 07/07/2011 17:42:21 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[SolicitudCotizacion](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EmpId] [smallint] NOT NULL,
	[ClienteId] [int] NULL,
	[UsuarioId] [varchar](30) NULL,
	[VendedorId] [int] NULL,
	[MaterialId] [int] NULL,
	[LineaId] [int] NULL,
	[Fecha] [datetime] NULL,
	[TipoProductoId] [int] NULL,
	[Producto] [varchar](100) NULL,
	[ProductoBase] [decimal](10, 2) NULL,
	[ProductoAltura] [decimal](10, 2) NULL,
	[ProductoFondo] [decimal](10, 2) NULL,
	[MaterialBase] [decimal](10, 2) NULL,
	[MaterialAltura] [decimal](10, 2) NULL,
	[MaterialFondo] [decimal](10, 2) NULL,
	[Tintas1Cara] [int] NULL,
	[Tintas2Cara] [int] NULL,
	[Cuatricromia] [bit] NULL,
	[Troquel] [bit] NULL,
	[Cantidades] [varchar](100) NULL,
	[Observaciones] [varchar](500) NULL,
	[Rendimiento] [decimal](10, 2) NULL,
	[Montaje] [decimal](10, 2) NULL,
	[Cubrimiento] [decimal](10, 2) NULL,
	[CotizacionId] [int] NULL,
	[Aplicada] [bit] NULL,
 CONSTRAINT [PK_SolicitudCotizacion] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[SolicitudCotizacion]  WITH CHECK ADD  CONSTRAINT [FK_SolicitudCotizacion_TipoProducto] FOREIGN KEY([TipoProductoId])
REFERENCES [dbo].[TipoProducto] ([Id])
GO

ALTER TABLE [dbo].[SolicitudCotizacion] CHECK CONSTRAINT [FK_SolicitudCotizacion_TipoProducto]
GO

ALTER TABLE [dbo].[SolicitudCotizacion] ADD  CONSTRAINT [DF_SolicitudCotizacion_Aplicada]  DEFAULT ((0)) FOR [Aplicada]
GO

/****** Object:  Table [dbo].[TipoProducto]    Script Date: 07/07/2011 17:46:17 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TipoProducto]') AND type in (N'U'))
DROP TABLE [dbo].[TipoProducto]
GO


/****** Object:  Table [dbo].[TipoProducto]    Script Date: 07/07/2011 17:46:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[TipoProducto](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TipoProducto] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Material' AND COLUMN_NAME = 'activo')
  ALTER TABLE Material ADD activo BIT NULL
GO

update material set activo = 1

GO

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Cliente' AND COLUMN_NAME = 'Cliente_Contacto_Correo')
  ALTER TABLE Cliente ADD Cliente_Contacto_Correo VARCHAR(50) NULL
GO

update Cliente set Cliente_Contacto_Correo = '' where Cliente_Contacto_Correo is null